package org.springsource.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.util.StringUtils;

public class StringUtilityDashes {
	public static final String removeWhitespaces(String inputString){
		String trimmed = StringUtils.trimWhitespace(inputString);
		return trimmed.replace("-"," ");
	}
	public static String extractUrls(String value) {
		if (value == null)
			return "";
		String urlPattern = "((https?|ftp|gopher|telnet|file):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";
		Pattern p = Pattern.compile(urlPattern, Pattern.CASE_INSENSITIVE);
		Matcher m = p.matcher(value);
		String result = "";
		while (m.find()) {
			result = value.substring(m.start(0), m.end(0));
		}
		return result;
	}
	
	public List<String> extractUrlsList(String value){
	    if (value == null) return  Collections.emptyList();
	    List<String> result = new ArrayList<String>();
	   String urlPattern = "((https?|ftp|gopher|telnet|file):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";
	    Pattern p = Pattern.compile(urlPattern,Pattern.CASE_INSENSITIVE);
	    Matcher m = p.matcher(value);
	    while (m.find()) {
	        result.add(value.substring(m.start(0),m.end(0)));
	    }
	    return result;
	}
}
